//
//  ZHAnchorTableCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "ZHAnchorTableCell.h"
#import "BaseLabel.h"
#import "Masonry.h"
#import "UIButton+WebCache.h"
#import "ZHListModel.h"
@interface ZHAnchorTableCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property (nonatomic,strong)UIButton *leftButton;

@property (nonatomic,strong)UIButton *middleButton;

@property (nonatomic,strong)UIButton *rightButton;

@property (nonatomic,strong)BaseLabel *leftLabel;
@property (nonatomic,strong)BaseLabel *middleLabel;
@property (nonatomic,strong)BaseLabel *rightLabel;

@property (nonatomic,strong)BaseLabel *topLabel;
@property (nonatomic,strong)BaseButton *moreButton;
@end

@implementation ZHAnchorTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView{

    UIImageView *topImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:topImageView];
    topImageView.image = [UIImage imageNamed:@"findsection_logo@2x.png"];
    
    _topLabel = [[BaseLabel alloc]init];
    [self.contentView addSubview:_topLabel];
    
    _leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_leftButton];
    
    _middleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_middleButton];
    
    _rightButton = [BaseButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_rightButton];
    
    _leftLabel = [[BaseLabel alloc]init];
    _leftLabel.numberOfLines = 0;
    [self.contentView addSubview:_leftLabel];
    
    _middleLabel = [[BaseLabel alloc]init];
    _middleLabel.numberOfLines = 0;
    [self.contentView addSubview:_middleLabel];
    
    _rightLabel = [[BaseLabel alloc]init];
    _rightLabel.numberOfLines = 0;
    [self.contentView addSubview:_rightLabel];
    
    self.moreButton = [BaseButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:_moreButton];
    [_moreButton setBackgroundImage:[UIImage imageNamed:@"liveRadioSectionMore_Normal@2x.png"] forState:UIControlStateNormal];
    [_moreButton setBackgroundImage:[UIImage imageNamed:@"liveRadioSectionMore_High@2x.png"] forState:UIControlStateHighlighted];
    [_moreButton addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [_topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(@40);
        make.top.mas_equalTo(@7);
        make.width.mas_equalTo(SCREEN_WIDTH_ZH / 3 -20);
        make.height.mas_equalTo(@40);
        
    }];
    
    [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(_topLabel.mas_centerY);
        make.right.equalTo(_topLabel.mas_left).offset(-10);
        make.height.mas_equalTo(@10);
    }];
    
    [_moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(@(-40));
        make.centerY.equalTo(_topLabel);
        make.height.mas_equalTo(@17);
    }];
    
    [_leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(@15);
        make.top.mas_equalTo(_topLabel.mas_bottom).offset(2);
        make.width.equalTo(_topLabel);
        make.height.mas_equalTo(@100);
        
    }];
    [_middleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_leftButton.mas_right).offset(15);
        make.top.equalTo(_leftButton.mas_top);
        make.width.equalTo(_leftButton.mas_width);
        make.height.equalTo(_leftButton.mas_height);
        
    }];
    [_rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_leftButton.mas_top);
        make.left.equalTo(_middleButton.mas_right).offset(15);
        make.width.equalTo(_leftButton.mas_width);
        make.height.equalTo(_leftButton.mas_height);
        
    }];
    
    [_leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
//        make.left.mas_equalTo(@15);
        make.top.equalTo(_leftButton.mas_bottom).offset(5);
        make.left.equalTo(_leftButton.mas_left);
        make.width.equalTo(_leftButton.mas_width);
        make.height.equalTo(_topLabel.mas_height);
    }];
    
    [_middleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_leftLabel);
        make.left.width.equalTo(_middleButton);
        make.height.equalTo(_topLabel);
    }];
    [_rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_leftLabel);
        make.left.width.equalTo(_rightButton);
        make.height.equalTo(_topLabel);
    }];
  
    [_leftButton addTarget:self action:@selector(leftAction:) forControlEvents:UIControlEventTouchUpInside];
    [_rightButton addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    [_middleButton addTarget:self action:@selector(middleAction:) forControlEvents:UIControlEventTouchUpInside];
    
   
    
}

- (void)setBigModel:(ZHListBigModel *)bigModel{
    // 更多
    _moreButton.tag = [bigModel.myId integerValue] + 2050;
    // 类别
    _topLabel.text = bigModel.title;
    _topLabel.font = [UIFont systemFontOfSize:15.5];
    // 图片
    [_leftButton sd_setBackgroundImageWithURL:[NSURL URLWithString:bigModel.listArray[0][@"smallLogo"]] forState:UIControlStateNormal placeholderImage:PLACEHOLDER_IMAGE];
    [_middleButton sd_setBackgroundImageWithURL:[NSURL URLWithString:bigModel.listArray[1][@"smallLogo"]] forState:UIControlStateNormal placeholderImage:PLACEHOLDER_IMAGE];
    [_rightButton sd_setBackgroundImageWithURL:[NSURL URLWithString:bigModel.listArray[2][@"smallLogo"]] forState:UIControlStateNormal placeholderImage:PLACEHOLDER_IMAGE];
    // nickname
    _leftLabel.text = bigModel.listArray[0][@"nickname"];
    _middleLabel.text = bigModel.listArray[1][@"nickname"];
    _rightLabel.text = bigModel.listArray[2][@"nickname"];
    _leftLabel.font = UIFONT15;
    _middleLabel.font = UIFONT15;
    _rightLabel.font = UIFONT15;
    _leftLabel.textAlignment = NSTextAlignmentCenter;
    _rightLabel.textAlignment = NSTextAlignmentCenter;
    _middleLabel.textAlignment = NSTextAlignmentCenter;
    
    _leftButton.tag = [bigModel.listArray[0][@"uid"] integerValue];
    _middleButton.tag = [bigModel.listArray[1][@"uid"] integerValue];
    _rightButton.tag = [bigModel.listArray[2][@"uid"] integerValue];
    
    _leftName = bigModel.listArray[0][@"nickname"];
    _middleName = bigModel.listArray[1][@"nickname"];
    _rightName = bigModel.listArray[2][@"nickname"];
    
    _name = bigModel.name;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 3;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentifier = @"UICollectionViewCell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    return cell;
}
- (void)moreAction:(BaseButton *)btn{
    NSLog(@"zh===%@",_name);
    [self.anchorTableCellDelegate presentToMoreViewController:btn.tag name:_name];
}

- (void)leftAction:(UIButton *)btn{
    [self.anchorTableCellDelegate presentToNextViewController:btn.tag name:_leftName];
    
}

- (void)middleAction:(UIButton *)btn{
    [self.anchorTableCellDelegate presentToNextViewController:btn.tag name:_middleName];
}

- (void)rightAction:(UIButton *)btn{
    [self.anchorTableCellDelegate presentToNextViewController:btn.tag name:_rightName];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
